/**
 * Copyright (c) 2017 ShopJsp. All Rights Reserved.
 * ============================================================================
 * 版权所有 2011 - 今 北京华宇盈通科技有限公司，并保留所有权利。
 * ----------------------------------------------------------------------------
 * 提示：在未取得SHOPJSP商业授权之前，您不能将本软件应用于商业用途，否则SHOPJSP将保留追究的权力。
 * ----------------------------------------------------------------------------
 * 官方网站：http://www.shopjsp.com
 * ============================================================================
 * @author 张丁方
 * @CreateTime 2017-3-29 15:21:46
 */
package com.hyyt.shopjsp.product.service.imp;

import com.hyyt.shopjsp.product.dao.ShopProductInfoDAO;
import com.hyyt.shopjsp.product.pojo.*;
import com.hyyt.shopjsp.product.service.*;
import com.hyyt.shopjsp.product.vo.*;
import com.hyyt.shopjsp.store.info.pojo.ShopShopInfo;
import com.hyyt.shopjsp.store.info.service.IShopShopInfoService;
import com.hyyt.shopjsp.util.common.StringStaticKey;
import com.hyyt.shopjsp.util.common.Utils;
import com.hyyt.shopjsp.util.date.DateUtil;
import com.hyyt.shopjsp.util.image.ImageUtil;
import com.hyyt.shopjsp.util.jcaptcha.QRCode;
import com.hyyt.shopjsp.util.json.FastJsonUtils;
import com.hyyt.shopjsp.util.number.SerialNumberUtil;
import com.hyyt.shopjsp.util.redis.util.RedisDataReadUtil;
import com.hyyt.shopjsp.util.upload.FileUploadUtil;
import com.hyyt.shopjsp.util.upload.UploadResult;
import net.sf.json.JSONArray;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.*;

@Service
public class ShopProductInfoService implements IShopProductInfoService {
    private static  final Logger logger = Logger.getLogger(IShopProductInfoService.class);

    @Resource
    private ShopProductInfoDAO shopProductInfoDAO;
    @Resource
    private IShopBrandService shopBrandService;
    @Resource
    private IShopProductImgService shopProductImgService;
    @Resource
    private IShopProductAttributeService shopProductAttributeService;
    @Resource
    private IShopProductAttributeValueService shopProductAttributeValueService;
    @Resource
    private IShopProductAttributeIndexService shopProductAttributeIndexService;
    @Resource
    private IShopProductParameterService shopProductParameterService;
    @Resource
    private IShopProductParameterValueService shopProductParameterValueService;
    @Resource
    private IShopSpecificationService shopSpecificationService;
    @Resource
    private IShopSpecificationValueService shopSpecificationValueService;
    @Resource
    private IShopProductSpecificationValueService shopProductSpecificationValueService;
    @Resource
    private IShopShopProCategoryRelationService shopShopProCategoryRelationService;
    @Resource
    private IShopProductInfoDetailService shopProductInfoDetailService;
    /**店铺service**/
    @Resource
    private IShopShopInfoService shopShopInfoService;
    /**店铺内部分类service**/
    @Resource
    private IShopShopProCategoryService shopShopProCategoryService;
    /**商品分类service**/
    @Resource
    private IShopProductTypeService shopProductTypeService;

    /**
     * 删除指定ID的SHOP_商品
     *
     * @param id SHOP_商品ID
     */
    @Override
    public void deleteShopProductInfo(Integer id) {
        shopProductInfoDAO.delete(id);
    }

    /**
     * 删除指定ID集合的SHOP_商品
     *
     * @param ids SHOP_商品ID集合
    */
    public void deleteShopProductInfo(Collection<Integer> ids){
        shopProductInfoDAO.batchDelete(ids);
    }

    /**
     * 根据ID加载一个SHOP_商品
     *
     * @param id SHOP_商品ID
     * @return SHOP_商品
     */
    @Override
    public ShopProductInfo loadShopProductInfo(Integer id) {
        return shopProductInfoDAO.load(id);
    }

    /**
    * 查询所有的SHOP_商品，通常有最多取30000条记录的限制
    *
    * @return 所有的SHOP_商品，通常有最多取30000条记录的限制
    */
    @Override
    public List<ShopProductInfo> queryAllShopProductInfo() {
        return shopProductInfoDAO.queryAll();
    }

    /**
     * 查询SHOP_商品
     *
     * @param params 查询参数，为key-value形式
     * @return SHOP_商品集合
     */
    @Override
    public List<ShopProductInfo> queryShopProductInfo(Map<String, Object> params) {
        return shopProductInfoDAO.query(params);
    }

    /**
     * 查询 SHOP_商品集合
     *
     * @param params   查询参数，没有则传null,分页参数key为“sortColumns”
     * @param startRow 起始行数（不含起始行的数据）
     * @param rowSize  要查询记录数
     * @return SHOP_商品集合
     */
    @Override
    public List<ShopProductInfo> queryProductList(Map<String, Object> params, int startRow, int rowSize) {
        return shopProductInfoDAO.query(params, startRow, rowSize);
    }

    /**
     * 查询SHOP_商品
     *
     * @param params   查询参数，没有则传null,分页参数key为“sortColumns”
     * @param startRow 起始行数（不含起始行的数据）
     * @param rowSize  要查询记录数
     * @return SHOP_商品集合
     */
    @Override
    public List<Map<String,Object>>  queryShopProductInfo(Map<String, Object> params, int startRow, int rowSize) {
        return shopProductInfoDAO.query("queryProductList", params, startRow, rowSize);
    }

    /**
     * 关联查询SHOP_商品
     *
     * @param params   查询参数，没有则传null,分页参数key为“sortColumns”
     * @param startRow 起始行数（不含起始行的数据）
     * @param rowSize  要查询记录数
     * @return SHOP_商品集合
     */
    @Override
    public List<ShopProductInfo> queryListProductInfo(Map<String, Object> params, int startRow, int rowSize) {
    	return shopProductInfoDAO.query("listProductByType", params, startRow, rowSize);
    }

    /**
     * 统计SHOP_商品
     *
     * @param params 查询参数，没有则传null,分页参数key为“sortColumns”
     * @return 结果集记录数
     */
    @Override
    public int countShopProductInfo(Map<String, Object> params) {
        return shopProductInfoDAO.count(params);
    }
    /**
     * 关联统计SHOP_商品
     *
     * @param params 查询参数，没有则传null,分页参数key为“sortColumns”
     * @return 结果集记录数
     */
    @Override
    public int countProductInfo(Map<String, Object> params) {
    	return shopProductInfoDAO.count("countProductByType", params);
    }

    /**
     * 添加抢购时展示的商品列表
     * @param params
     * @param startRow
     * @param rowSize
     * @return
     */
    public List<ShopProductInfo> queryProductInfoList(Map<String, Object> params, int startRow, int rowSize){
        return shopProductInfoDAO.query("queryProductInfoList", params, startRow, rowSize);
    }

    /**
     * 添加抢购时展示的商品数量
     * @param params
     * @return
     */
    public int queryProductInfoCount(Map<String,Object> params){
        return shopProductInfoDAO.count("queryProductInfoCount",params);
    }

    /**
     * 微信语音识别结果搜索的商品列表，查询8条
     * @param params
     * @return
     */
    public List<ShopProductInfo> queryWxRecongnitionProductInfoList(Map<String, Object> params){
        return shopProductInfoDAO.query("queryWxRecongnitionProductInfoList", params);
    }

    /**
     * 产品列表查询商品
     *
     * @param params   查询参数，没有则传null,分页参数key为“sortColumns”
     * @param startRow 起始行数（不含起始行的数据）
     * @param rowSize  要查询记录数
     * @return SHOP_商品集合
     */
    @Override
    public List<ShopProductInfo> queryProductInfo(Map<String, Object> params, int startRow, int rowSize) {
        return shopProductInfoDAO.queryProductInfoRelationShopInfo(params, startRow, rowSize);
    }

    /**
     * 获取商品的组Id
     * @return
     */
    @Override
    public int loadMaxGoods() {
        return shopProductInfoDAO.count("loadMaxGoods", null);
    }

    /**
     * 添加商品
     *
     * @param shopProCategoryId  店铺商品内部分类
     * @param productInfo  商品对象
     * @param productImageListVo  商品图片虚拟对象
     * @param productAttrListVo  商品属性虚拟对象
     * @param paramGroupInfoVo  商品参数组信息虚拟对象
     * @param paramGroupVo  商品参数组虚拟对象
     * @param specifications  规格
     * @param detailContent  商品详情信息
     */
    @Override
    public void saveShopProductInfo(Integer shopProCategoryId,  ShopProductInfo productInfo, ProductImageListVo productImageListVo, ProductAttrListVo productAttrListVo, ParamGroupInfoVo paramGroupInfoVo, ParamGroupVo paramGroupVo, String specifications, String detailContent) {
        List<ParamGroup> paramGroupList = paramGroupVo.getParamGroupList();
        List<ParamGroupInfo> paramGroupInfoList = paramGroupInfoVo.getParamGroupInfoList();
        List<ProductAttrValueVo> productAttrValueVoList = productAttrListVo.getProductAttrValueVoList();

        //1、设置商品参数组信息
        paramGroupList=setParamGroupListByParamGroupInfoList(paramGroupList,paramGroupInfoList);
        //商品参数处理--直接存在商品表中，不需要进行检索，无中间表对应关系
        if (Utils.objectIsNotEmpty(paramGroupList)) {
            JSONArray jbListPG = JSONArray.fromObject(paramGroupList);//json格式的商品参数
            productInfo.setProductParametersValue(jbListPG.toString());
        }

        //2、商品和商品属性关系表的处理
        List<ShopProductAttributeIndex> paiList = new ArrayList<ShopProductAttributeIndex>();
        List<ProductAttrValueVo> saveProductAttrValueVoList =new ArrayList<ProductAttrValueVo>();
        if (Utils.objectIsNotEmpty(productAttrValueVoList)) {
            for (ProductAttrValueVo pavv : productAttrValueVoList) {
                if(Utils.objectIsNotEmpty(pavv.getValue())){//属性值不为空的可存库
                    ShopProductAttributeIndex pai = new ShopProductAttributeIndex();
                    pai.setProductAttrId(Integer.parseInt(pavv.getName()));
                    pai.setAttrValueId(Integer.parseInt(pavv.getValue()));
                    paiList.add(pai);
                    saveProductAttrValueVoList.add(pavv);
                }else{//属性值为空的不可存库
                    continue;
                }
            }
        }

        //3、商品对象冗余存储属性及属性值关系的json信息
        if (Utils.objectIsNotEmpty(saveProductAttrValueVoList)) {
            JSONArray jbListPA = JSONArray.fromObject(saveProductAttrValueVoList);//json格式的商品属性
            productInfo.setProductAttributeValue(jbListPA.toString());
        }

        //4、运费的处理
        if (productInfo.getIsChargeFreight() == 1) {//不收取运费
            productInfo.setFreightPrice(new BigDecimal(0));//运费==0.0
        }
        productInfo.setProductTypeId(productInfo.getCategory_level3());
        productInfo.setCreateDate(DateUtil.getCurrentTimestamp());
        productInfo.setUpdateDate(DateUtil.getCurrentTimestamp());
        productInfo.setIsNew(1);//是否为新商品：是
        productInfo.setIsTop(0);//是否置顶：否
        productInfo.setIsHot(0);//是否热销：否
        productInfo.setIsPass(3);//是否通过审核：待审核
        productInfo.setIsPutSale(1);//是否上架：未上架
        productInfo.setIsRecommend(0);//是否推荐：否
        productInfo.setTotalSales(0);//销售量：0
        productInfo.setImageType(1);//设置商品图片类型为图片 1:图片，2：视频

        //5、取分组的最大值
        Integer maxGoods = loadMaxGoods();
        if (maxGoods == null) {
            productInfo.setGoods(1);
        } else {
            productInfo.setGoods(maxGoods + 1);
        }

        //6、根据多条的规格和规格值组，生成多个商品
        saveProductInfoList(shopProCategoryId, productInfo, specifications, productImageListVo.getProductImageList(), paiList,detailContent);

    }

    /**
     * 根据多条的规格和规格值组，生成多个商品
     * @param shopProCategoryId  店铺商品内部分类
     * @param productInfo  商品对象
     * @param specifications  规格
     * @param productImageList  商品组图集合
     * @param paiList  商品属性值集合
     * @param detailContent  商品详情信息
     */
    public void saveProductInfoList(Integer shopProCategoryId, ShopProductInfo productInfo, String specifications, List<ShopProductImg> productImageList,  List<ShopProductAttributeIndex> paiList,String detailContent) {
        //1、重新构建商品名称（带品牌的）
        if (productInfo.getBrandId() != 1) {
            ShopBrand brand = shopBrandService.loadShopBrand(productInfo.getBrandId());
            if(Utils.objectIsNotEmpty(brand)){
                productInfo.setProductName(brand.getBrandName() + " " + productInfo.getProductName());
            }
        }

        //2、添加商品的规格和规格值
        try {
            //2.1、规格及规格值信息不为空表示组合商品的添加
            if (Utils.objectIsNotEmpty(specifications)) {
                String[] firstSplit = specifications.split(",");//根据规格组拼生成一个新商品的规格组
                //更改商品在列表显示的状态
                for (int i = 0; i < firstSplit.length; i++) {
                    productInfo.setSku(SerialNumberUtil.generateSkuCode());
                    //第一个商品是主商品需要在列表中显示，与其关联生成的商品不需要再列表中展示
                    if (i > 0) {//isShow 0：不显示， 1：显示；
                        productInfo.setIsShow(0);
                    }else{
                        productInfo.setIsShow(1);//将第一个设置为主商品
                    }
                    //2.1.1、保存商品基本信息
                    saveBasicShopProductInfo(productInfo);
                    //2.1.2、保存商品和商家创建的店铺商品内部分类的关系
                    saveShopShopProCategoryRelation(productInfo.getProductId(),shopProCategoryId);
                    //2.1.3、所有派生的商品默认保存统一的图片组图
                    saveShopProductImg(productInfo.getProductId(),productImageList);
                    //2.1.4、保存商品详情信息
                    saveShopProductInfoDetail(productInfo.getProductId(),detailContent);
                    //2.1.5、保存商品和商品属性关系
                    saveShopProductAttributeIndex(productInfo,paiList);
                    //2.1.6、获取商品的规格值并建立商品和规格值的中间表对应关系
                    saveShopProductSpecificationValue(productInfo,firstSplit[i]);
                }
            } else { //2.2、规格及规格值信息为空表示单一商品的添加
                productInfo.setIsShow(1);//isShow 0：不显示， 1：显示；
                productInfo.setSku(SerialNumberUtil.generateSkuCode());
                productInfo.setProductFullName(productInfo.getProductName());
                //2.2.1、保存商品基本信息
                saveBasicShopProductInfo(productInfo);
                //2.2.2、保存商品和商家创建的店铺商品内部分类的关系
                saveShopShopProCategoryRelation(productInfo.getProductId(),shopProCategoryId);
                //2.2.3、保存商品组图信息
                saveShopProductImg(productInfo.getProductId(),productImageList);
                //2.2.4、保存商品详情信息
                saveShopProductInfoDetail(productInfo.getProductId(),detailContent);
                //2.2.5、保存商品和商品属性关系
                saveShopProductAttributeIndex(productInfo,paiList);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * 1、保存商品基础信息
     *
     * @param productInfo SHOP_商品
     * @return 更新后的SHOP_商品
     */
    @Override
    public void saveBasicShopProductInfo(ShopProductInfo productInfo) {
        shopProductInfoDAO.insert(productInfo);
    }


    /**
     * 2、保存商品和商家创建的店铺商品内部分类的关系
     *
     * @param productId 商品Id
     * @param shopProCategoryId  店铺商品内部分类Id
     */

    public void saveShopShopProCategoryRelation(Integer productId,Integer shopProCategoryId){
        ShopShopProCategoryRelation sspcr = new ShopShopProCategoryRelation();
        sspcr.setProductId(productId);
        sspcr.setShopProCategoryId(shopProCategoryId);
        shopShopProCategoryRelationService.saveShopShopProCategoryRelation(sspcr);
    }

    /**
     * 3、保存商品和商家创建的店铺商品内部分类的关系
     *
     * @param productId 商品Id
     * @param productImageList  商品图片组图集合
     */
    public void saveShopProductImg(Integer productId,List <ShopProductImg> productImageList){
        if (Utils.objectIsNotEmpty(productImageList)) {
            productImageList=this.removeNullObjectForImageList(productImageList) ;
            for (ShopProductImg spi : productImageList) {
                spi.setProductId(productId);
                shopProductImgService.saveShopProductImg(spi);
            }
        }
    }

    /**
     * 4、保存商品和商品详情关系
     *
     * @param productId 商品Id
     * @param detailContent 商品详情信息
     */
    public void saveShopProductInfoDetail(Integer productId,String detailContent){
        if (Utils.objectIsNotEmpty(detailContent)) {
            ShopProductInfoDetail spid=new ShopProductInfoDetail();
            spid.setProductId(productId);
            spid.setDetailContent(detailContent);
            shopProductInfoDetailService.saveShopProductInfoDetail(spid);
        }
    }

    /**
     * 5、通过商品分类Id查询所有的商品属性及属性值信息
     *
     * @param productTypeId 商品分类Id
     * @return 返回商品属性集合
     */
    @Override
    public List<ShopProductAttribute> getProductAttributeAndValueList(Integer productTypeId){
        Map params = new HashMap();
        List<ShopProductAttribute> productAttributeList = new ArrayList<>();
        List<ShopProductAttribute> removeList = new ArrayList<>();//存放没有属性值的属性集合,用于删除
        if (Utils.objectIsNotEmpty(productTypeId)) {
            params.put("productTypeId", productTypeId);
            // 1、查询商品属性
            productAttributeList = shopProductAttributeService.queryShopProductAttribute(params);
            params.clear();
            // 2、查询属性值集合并封装到属性对象中
            if (Utils.collectionIsNotEmpty(productAttributeList)) {
                for(int i=0;i<productAttributeList.size();i++){
                    ShopProductAttribute spa=productAttributeList.get(i);
                    params.put("productAttrId",spa.getProductAttrId());
                    List<ShopProductAttributeValue> productAttributeValueList = shopProductAttributeValueService.queryShopAttributeValue(params);
                    if(Utils.collectionIsNotEmpty(productAttributeValueList)){
                        spa.setShopProductAttributeValueList(productAttributeValueList);
                    }else{
                        removeList.add(spa);
                    }
                }
                //3、删除存放没有属性值的属性
                for(int i=0;i<removeList.size();i++){
                    productAttributeList.remove(removeList.get(i));
                }
            }
        }
        params.clear();
        return productAttributeList;
    }

    /**
     * 6、保存商品和商品属性关系
     *
     * @param productInfo 商品对象
     * @param paiList  商品属性集合
     */
    public void saveShopProductAttributeIndex(ShopProductInfo productInfo,List <ShopProductAttributeIndex> paiList){
        if (Utils.objectIsNotEmpty(paiList)) {
            for (ShopProductAttributeIndex pai : paiList) {
                ShopProductAttributeIndex spai = new ShopProductAttributeIndex();
                spai.setAttrValueId(pai.getAttrValueId());
                spai.setProductAttrId(pai.getProductAttrId());
                spai.setProductId(productInfo.getProductId());
                spai.setProductTypeId(productInfo.getProductTypeId());
                shopProductAttributeIndexService.saveShopProductAttributeIndex(spai);
            }
        }
    }

    /**
     * 7、通过商品分类Id查询所有的商品规格参数及参数值信息
     *
     * @param productTypeId 商品分类Id
     * @return 返回商品规格参数集合
     */
    @Override
    public List<ShopProductParameter> getProductParameterAndValueList(Integer productTypeId){
        Map params = new HashMap();
        List<ShopProductParameter> productParameterList = new ArrayList<>();
        List<ShopProductParameter> removeList = new ArrayList<>();//存放没有规格参数值的规格参数集合,用于删除
        if (Utils.objectIsNotEmpty(productTypeId)) {
            params.put("productTypeId", productTypeId);
            // 1、查询商品规格参数
            productParameterList = shopProductParameterService.queryShopProductParameter(params);
            params.clear();
            // 2、查询规格参数值集合并封装到规格参数对象中
            if (Utils.collectionIsNotEmpty(productParameterList)) {
                for(int i=0;i<productParameterList.size();i++){
                    ShopProductParameter spp=productParameterList.get(i);
                    params.put("paramId",spp.getParamId());
                    List<ShopProductParameterValue> productParameterValueList = shopProductParameterValueService.queryShopProductParameterValue(params);
                    if(Utils.collectionIsNotEmpty(productParameterValueList)){
                        spp.setShopProductParameterValueList(productParameterValueList);
                    }else{
                        removeList.add(spp);
                    }
                }
                //3、删除存放没有规格参数值的规格参数
                for(int i=0;i<removeList.size();i++){
                    productParameterList.remove(removeList.get(i));
                }
            }
        }
        params.clear();
        return productParameterList;
    }



    /**
     * 8、通过商品分类Id查询所有的商品规格组及值信息
     *
     * @param productTypeId 商品分类Id
     * @return 返回商品规格组集合
     */
    @Override
    public List<ShopSpecification> getProductSpecificationList(Integer productTypeId){
        Map params = new HashMap();
        List<ShopSpecification> productSpecificationList = new ArrayList<>();
        if (Utils.objectIsNotEmpty(productTypeId)) {
            params.put("productTypeId", productTypeId);
            // 1、查询商品规格组
            productSpecificationList = shopSpecificationService.queryShopSpecification(params);
        }
        params.clear();
        return productSpecificationList;
    }

    /**
     * 9、通过商品分类Id查询所有的商品规格组及值信息
     *
     * @param specificationId 商品规格组Id
     * @return 返回商品规格组对应值集合
     */
    @Override
    public List<ShopSpecificationValue> getSpecificationValueListBySpecificationId(Integer specificationId){
        Map params = new HashMap();
        List<ShopSpecificationValue> productSpecificationValueList = new ArrayList<>();
        if (Utils.objectIsNotEmpty(specificationId)) {
            params.put("specificationId", specificationId);
            // 1、查询商品规格组对应值信息
            productSpecificationValueList = shopSpecificationValueService.queryShopSpecificationValue(params);
        }
        params.clear();
        return productSpecificationValueList;
    }

    /**
     * 10、获取商品的规格值并建立商品和规格值的中间表对应关系
     *
     * @param productInfo 商品对象
     * @param firstSplitString 商品规格及规格值子串信息
     */
    public void saveShopProductSpecificationValue(ShopProductInfo productInfo,String firstSplitString){
        String[] secondSplit = firstSplitString.split("&");//把一个新的商品规格组解析成规格对应规格值
        StringBuffer productFullNameSb = new StringBuffer();
        productFullNameSb.append(productInfo.getProductName() + " [");
        for (String ss : secondSplit) {
            String[] thirdSplit = ss.split("=");//把规格和规格值分开
            String[] fourthSplit = thirdSplit[0].split("_");//解析规格前缀，如：specification_1
            if ("kucun".equals(thirdSplit[0])) {//库存标识
                productInfo.setStoreNumber(Utils.parseInt(thirdSplit[1], 0));
                continue;
            } else if ("bianhao".equals(thirdSplit[0])) {//编号标识
                productInfo.setProductCode(thirdSplit[1]);
                continue;
            }
            //规格值
            ShopProductSpecificationValue productSpecificationValue = new ShopProductSpecificationValue();
            productSpecificationValue.setProductId(productInfo.getProductId());
            //规格值id
            productSpecificationValue.setSpecificationValueId(Integer.parseInt(thirdSplit[1]));
            //当前分组号
            productSpecificationValue.setGoodId(productInfo.getGoods());
            //规格id
            productSpecificationValue.setSpecificationId(Integer.parseInt(fourthSplit[1]));
            shopProductSpecificationValueService.saveShopProductSpecificationValue(productSpecificationValue);
            //获取规格值名称并追加到商品全名称中
            ShopSpecificationValue ssv = shopSpecificationValueService.loadShopSpecificationValue(Integer.parseInt(thirdSplit[1]));
            productFullNameSb.append(ssv.getName() + ",");
        }
        productFullNameSb.deleteCharAt(productFullNameSb.lastIndexOf(","));
        productFullNameSb.append("]");
        productInfo.setProductFullName(productFullNameSb.toString());//重置商品的全名称，并进行修改操作
        updateBasicShopProductInfo(productInfo);//更新商品基本信息
    }

    /**
     * 更新商品信息
     *
     * @param shopProCategoryId  店铺商品内部分类
     * @param productInfo  商品对象
     * @param productImageListVo  商品图片虚拟对象
     * @param productAttrListVo  商品属性虚拟对象
     * @param paramGroupInfoVo  商品参数组信息虚拟对象
     * @param paramGroupVo  商品参数组虚拟对象
     * @param detailContent  商品详情信息
     */
    @Override
    public void updateShopProductInfo(Integer shopProCategoryId,  ShopProductInfo productInfo, ProductImageListVo productImageListVo, ProductAttrListVo productAttrListVo, ParamGroupInfoVo paramGroupInfoVo, ParamGroupVo paramGroupVo,String detailContent) {
        if (Utils.objectIsNotEmpty(productInfo)) {
            if (Utils.objectIsNotEmpty(productInfo.getProductId())) {
                ShopProductInfo productInfoTemp = loadShopProductInfo(productInfo.getProductId());
                //1、把新修改的基本数据复制到原始数据里面
                productInfoTemp.setBrandId(productInfo.getBrandId());//品牌
                productInfoTemp.setProductTypeId(productInfo.getProductTypeId());//商品分类ID
                productInfoTemp.setLogoImg(productInfo.getLogoImg());//商品logo图片
                if (productInfo.getBrandId() != 1) {//构建商品名称
                    ShopBrand brand = shopBrandService.loadShopBrand(productInfo.getBrandId());
                    if(Utils.objectIsNotEmpty(brand)){
                        productInfo.setProductName(brand.getBrandName() + " " + productInfo.getProductName());
                    }
                }
                productInfoTemp.setProductName(productInfo.getProductName());
                String productFullName=productInfoTemp.getProductFullName();//根据修改的商品名称，更新商品全名称
                if(productFullName.indexOf("[")!=-1 && productFullName.indexOf("]")!=-1){//说明商品有规格组合并将规格信息追加到商品名称中
                    String subProductFullName=productFullName.substring(productFullName.indexOf("["),productFullName.indexOf("]")+1);//截取原来全名称中的规格子串，如：[S,灰色]
                    productInfoTemp.setProductFullName(productInfo.getProductName().trim()+" "+subProductFullName);//商品全名称：更新的商品名称+规格子串
                }else{//说明商品没有规格组合
                    productInfoTemp.setProductFullName(productInfo.getProductName().trim());//商品全名称：更新的商品名称+规格子串
                }
                productInfoTemp.setDescrible(productInfo.getDescrible());//商品描述
                productInfoTemp.setProductCode(productInfo.getProductCode());//商品编号
                productInfoTemp.setStoreNumber(productInfo.getStoreNumber());//库存
                productInfoTemp.setMarketPrice(productInfo.getMarketPrice());//市场价格
                productInfoTemp.setSalesPrice(productInfo.getSalesPrice());//销售价格
                productInfoTemp.setUpRatio(productInfo.getUpRatio());//上一级返利比例
                productInfoTemp.setSecRatio(productInfo.getSecRatio());//上二级返利比例
                productInfoTemp.setThiRatio(productInfo.getThiRatio());//上三级返利比例
                productInfoTemp.setGiveAwayCoinNumber(productInfo.getGiveAwayCoinNumber());//订单用户购买商品返利用户赠送的积分总额(用户购买商品所得)
                productInfoTemp.setDeliveryAddressProvince(productInfo.getDeliveryAddressProvince());//发货地-省份
                productInfoTemp.setDeliveryAddressCities(productInfo.getDeliveryAddressCities());//发货地-城市
                productInfoTemp.setNote(productInfo.getNote());//商品备注
                productInfoTemp.setWeight(productInfo.getWeight());//商品重量
                productInfoTemp.setMeasuringUnitName(productInfo.getMeasuringUnitName());//计量单位
                productInfoTemp.setPackingSpecifications(productInfo.getPackingSpecifications());//包装规格
                productInfoTemp.setBarCode(productInfo.getBarCode());//商品条形码
                productInfoTemp.setManufacturerModel(productInfo.getManufacturerModel());//制造商型号
                productInfoTemp.setSeoTitle(productInfo.getSeoTitle());//seo标题
                productInfoTemp.setSeoKeyWord(productInfo.getSeoKeyWord());//seo关键字
                productInfoTemp.setSeoDescription(productInfo.getSeoDescription());//seo描述
                productInfoTemp.setIsPutSale(1);//修改默认：未上架
                productInfoTemp.setIsPass(3);//修改默认：待审核


                //2、更新商品和店铺商品内部分类关系
                updateShopShopProCategoryRelation(productInfoTemp.getProductId(),shopProCategoryId);
                //3、更新商品图文详情信息
                updateShopProductInfoDetail(productInfoTemp.getProductId(),detailContent);
                //4、更新商品组图信息
                updateShopProductImage(productInfoTemp.getProductId(),productImageListVo);
                //5、更新商品属性值并更新商品和商品扩展属性的关系
                if (Utils.objectIsNotEmpty(productAttrListVo.getProductAttrValueVoList())) {
                    String jbListPA = FastJsonUtils.toJSONString(productAttrListVo.getProductAttrValueVoList());
                    productInfoTemp.setProductAttributeValue(jbListPA.toString());
                }
                shopProductAttributeIndexService.deleteShopProductAttributeIndex(productInfoTemp.getProductId());
                updateShopProductAttributeIndex(productInfoTemp,productAttrListVo);
                //6、设置商品参数组信息并更新商品参数值
                List<ParamGroup> paramGroupList=setParamGroupListByParamGroupInfoList(paramGroupVo.getParamGroupList(),paramGroupInfoVo.getParamGroupInfoList());
                if (Utils.objectIsNotEmpty(paramGroupList)) {
                    String jbListPG = FastJsonUtils.toJSONString(paramGroupList);
                    productInfoTemp.setProductParametersValue(jbListPG.toString());
                }
                //7、更新商品基本信息
                updateBasicShopProductInfo(productInfoTemp);
            }
        }
    }

    /**
     * 查询商品及关联信息
     *
     * @param productId 商品Id
     * @return 返回商品及关联信息集合
     */
    @Override
    public Map<String,Object> getShopProductAndRelationInfoByProductId(Integer productId) {
        Map<String,Object> params=new HashMap<String,Object>();
        Map<String,Object> shopProductAndRealtionInfoMap=new HashMap<String,Object>();
        //1、获取商品基本信息
        ShopProductInfo productInfo=shopProductInfoDAO.load(productId);
        shopProductAndRealtionInfoMap.put("productInfo",productInfo);
        //2、获取商品图文详情信息
        params.put("productId",productId);
        List<ShopProductInfoDetail> productInfoDetailList=shopProductInfoDetailService.queryShopProductInfoDetail(params);
        if(Utils.objectIsNotEmpty(productInfoDetailList)){
            ShopProductInfoDetail productInfoDetail=productInfoDetailList.get(0);
            shopProductAndRealtionInfoMap.put("productInfoDetail",productInfoDetail);
        }
        //3、获取商品组图信息
        List<ShopProductImg> productImgList=shopProductImgService.queryShopProductImg(params);
        shopProductAndRealtionInfoMap.put("productImgList",productImgList);
        //4、获取商品关联的扩展属性信息
        List<ShopProductAttributeIndex> productAttributeIndexList=shopProductAttributeIndexService.queryShopProductAttributeIndex(params);
        shopProductAndRealtionInfoMap.put("productAttributeIndexList",productAttributeIndexList);
        //5、获取商品规格及规格值信息
        params.clear();
        params.put("goodId",productInfo.getGoods());
        List<ShopProductSpecificationValue> shopProductSpecificationValueList=shopProductSpecificationValueService.queryShopProductSpecificationValue(params);
        shopProductAndRealtionInfoMap.put("shopProductSpecificationValueList",shopProductSpecificationValueList);
        return shopProductAndRealtionInfoMap;
    }


    /**
     * 查询规格对象
     *
     * @param specificationId 规格Id
     * @return 返回商品规格对象
     */
    @Override
    public ShopSpecification getShopSpecificationBySpecificationId(Integer specificationId) {
        return  shopSpecificationService.loadShopSpecification(specificationId);
    }

    /**
     * 查询规格对象
     *
     * @param specificationValueId 规格Id
     * @return 返回商品规格对象
     */
    @Override
    public ShopSpecificationValue getShopSpecificationValueBySpecificationValueId(Integer specificationValueId) {
        return  shopSpecificationValueService.loadShopSpecificationValue(specificationValueId);
    }


    /**
     * 查询商品和商品店铺内部分类信息
     *
     * @param productId 商品Id
     * @return 商品店铺内部分类对象
     */
    @Override
    public ShopShopProCategoryRelation getShopShopProCategoryRelationByProductId(Integer productId) {
        Map<String,Object> params=new HashMap<String,Object>();
        params.put("productId",productId);
        List <ShopShopProCategoryRelation> shopProCategoryRelationList =shopShopProCategoryRelationService.queryShopShopProCategoryRelation(params);
        ShopShopProCategoryRelation shopProCategoryRelation=null;
        if(Utils.objectIsNotEmpty(shopProCategoryRelationList)){
            shopProCategoryRelation=shopProCategoryRelationList.get(0);
        }
        return shopProCategoryRelation;
    }

    /**
     * 2、更新商品和商家创建的店铺商品内部分类的关系
     *
     * @param productId 商品Id
     * @param shopProCategoryId  店铺商品内部分类Id
     */
    public void updateShopShopProCategoryRelation(Integer productId,Integer shopProCategoryId){
        //店铺内部分类是否修改。若修改了，则修改中间表
        Map params = new HashMap();
        params.put("productId", productId);
        ShopShopProCategoryRelation sspcr = shopShopProCategoryRelationService.loadShopProCategoryRelationByParams(params);
        if (Utils.objectIsNotEmpty(sspcr) && sspcr.getShopProCategoryId().compareTo(shopProCategoryId) != 0) {
            //使用sql语句的方式对原始数据进行更新
            params.clear();
            params.put("shopProCategoryId", shopProCategoryId);
            params.put("productId", sspcr.getProductId());
            shopShopProCategoryRelationService.updateByProductId(params);
        } else {
            if (sspcr == null) {
                sspcr = new ShopShopProCategoryRelation();
                sspcr.setProductId(productId);
                sspcr.setShopProCategoryId(shopProCategoryId);
                shopShopProCategoryRelationService.saveShopShopProCategoryRelation(sspcr);
            }
        }

    }

    /**
     * 3、更新商品详情信息
     *
     * @param productId 商品Id
     * @param detailContent  商品详情信息
     */
    public void updateShopProductInfoDetail(Integer productId,String detailContent){
        Map<String,Object> params=new HashMap<>();
        if(Utils.objectIsNotEmpty(productId)){
            //根据商品Id查询商品详情对象
            ShopProductInfoDetail shopProductInfoDetail = shopProductInfoDetailService.loadShopProductInfoDetail(productId);
            if(Utils.objectIsNotEmpty(shopProductInfoDetail)){
                shopProductInfoDetail.setDetailContent(detailContent);
                shopProductInfoDetailService.updateShopProductInfoDetail(shopProductInfoDetail);
            }else{
                shopProductInfoDetail=new ShopProductInfoDetail();
                shopProductInfoDetail.setProductId(productId);
                shopProductInfoDetail.setDetailContent(detailContent);
                shopProductInfoDetailService.saveShopProductInfoDetail(shopProductInfoDetail);
            }
        }
    }

    /**
     * 4、更新商品组图信息
     *
     * @param productId 商品Id
     * @param productImageListVo 商品组图虚拟对象集合
     */
    public void updateShopProductImage(Integer productId,ProductImageListVo productImageListVo){
        if(Utils.objectIsNotEmpty(productImageListVo)){
            List<ShopProductImg> productImageList=productImageListVo.getProductImageList();
            if(Utils.objectIsNotEmpty(productImageList)){
                List<ShopProductImg> productImgList=this.removeNullObjectForImageList(productImageList) ;
                if(Utils.objectIsNotEmpty(productImgList)){
                    for(ShopProductImg spi:productImgList){
                        if(Utils.objectIsNotEmpty(spi.getProductImageId())){
                            shopProductImgService.updateShopProductImg(spi);
                        }else{//新增的图片
                            spi.setProductId(productId);
                            shopProductImgService.saveShopProductImg(spi);
                        }

                    }
                }
            }
        }
    }

    /**
     * 5、删除商品组图信息
     *
     * @param productImageId 商品图片Id
     */
    public void deleteProductImageByProductImageId(Integer productImageId){
        if(Utils.objectIsNotEmpty(productImageId)){
            shopProductImgService.deleteShopProductImg(productImageId);
        }
    }

    /**
     * 6、更新商品和商品扩展属性关系
     *
     * @param productInfo 商品对象
     * @param productAttrListVo 商品属性集合虚拟对象
     */
    public void updateShopProductAttributeIndex(ShopProductInfo productInfo,ProductAttrListVo productAttrListVo){
        List<ProductAttrValueVo> productAttrValueList = productAttrListVo.getProductAttrValueVoList();/**保存的商品的属性**/
        if (productAttrValueList != null) {
            for (ProductAttrValueVo pavv : productAttrValueList) {
                if (Utils.objectIsNotEmpty(pavv)) {
                    if(Utils.objectIsNotEmpty(pavv.getName()) && Utils.objectIsNotEmpty(pavv.getValue())){
                        ShopProductAttributeIndex spai = new ShopProductAttributeIndex();
                        spai.setProductAttrId(Integer.parseInt(pavv.getName()));
                        spai.setAttrValueId(Integer.parseInt(pavv.getValue()));
                        spai.setProductId(productInfo.getProductId());
                        spai.setProductTypeId(productInfo.getProductTypeId());
                        shopProductAttributeIndexService.saveShopProductAttributeIndex(spai);
                    }
                }
            }
        }
    }

    /**
     * 6、更新商品基本信息
     *
     * @param productInfo 商品对象
     */
    @Override
    public void updateBasicShopProductInfo(ShopProductInfo productInfo) {
        shopProductInfoDAO.update(productInfo);
    }

    /**
     * 处理商品的参数组以及参数值
     *
     * @param paramGroupList 参数组集合
     * @param paramGroupInfoList  参数组信息集合
     */
    public List<ParamGroup> setParamGroupListByParamGroupInfoList(List<ParamGroup> paramGroupList,List<ParamGroupInfo> paramGroupInfoList){
        List<ParamGroup> saveParamGroupList=new ArrayList<ParamGroup>();
        if (Utils.objectIsNotEmpty(paramGroupList)) {
            for (ParamGroup pg : paramGroupList) {
                List<ParamGroupInfo> pgiList = new ArrayList<ParamGroupInfo>();
                for (ParamGroupInfo pgi : paramGroupInfoList) {
                    if (pg.getParamGroupId().equals(pgi.getPgiId())) {
                        if(Utils.objectIsNotEmpty(pgi.getValue())){//参数值不为空的可存库
                            pgiList.add(pgi);
                        }else{//参数值为空的不可存库
                            continue;
                        }
                    }
                }
                if(Utils.objectIsNotEmpty(pgiList)){//无参数组信息不存储
                    pg.setParamGroupInfo(pgiList);
                    saveParamGroupList.add(pg);
                }
            }
        }
        return saveParamGroupList;
    }

    /**
     * 详情页滚动图片上传
     *
     * @param productImageInfo 图片流文件
     * @param subSysFolderName 子系统目录
     * @param imageInfoPath 图片存放目录
     * @param productImg  商品组图图片对象
     */
    public ShopProductImg uploadProductImage(MultipartFile productImageInfo, String subSysFolderName,String imageInfoPath, ShopProductImg productImg) {
        //原图
        UploadResult ur= FileUploadUtil.uploadImagesFile(productImageInfo, productImageInfo.getOriginalFilename(), subSysFolderName,imageInfoPath);
        String fileUrl=ur.getFileUrl();
        productImg.setSource(fileUrl);
        //原图片上传至服务器后的全路径
        String url = RedisDataReadUtil.getSysConfig(StringStaticKey.FILE_UPLOAD_ROOT) + "/" + fileUrl;
        //将路径new成文件
        File f = new File(url);
        //生成原文件名称
        String name = f.getName();
        //去文件名称（去除后缀.jpg）
        String[] nameArray = name.split("\\.");
        //原文件的父目录
        //Z:\thshop\shop\image\product\20140220
        String pathParent = f.getParent();
        //配置文件中上传文件路径的长度
        //Z:/thshop/
        String lstr = String.valueOf(RedisDataReadUtil.getSysConfig(StringStaticKey.FILE_UPLOAD_ROOT));
        int l = lstr.length();
        //生成大图
        productImg.setLarge(ImageUtil.scaleByHeightAndWidth(url, pathParent + "/" + nameArray[0] + "_large." + nameArray[1], 1000, 1000, true, l));
        //生成中图
        productImg.setMedium(ImageUtil.scaleByHeightAndWidth(url, pathParent + "/" + nameArray[0] + "_medium." + nameArray[1], 600, 600, true, l));
        //生成小图
        productImg.setThumbnail(ImageUtil.scaleByHeightAndWidth(url, pathParent + "/" + nameArray[0] + "_thumbnail." + nameArray[1], 200, 200, true, l));
        return productImg;
    }

    /**
     * 根据商品Id查询
     * @param productId
     * @return
     */
    @Override
    public Map<String,Object> getProductInfoById(Integer productId){
        Map<String,Object> resultMap=new HashMap<>();
        //获得商品相关信息
        Map<String, Object> productRelationMap = getShopProductAndRelationInfoByProductId(productId);
        ShopProductInfo shopProductInfo =(ShopProductInfo)productRelationMap.get("productInfo");
        //根据店铺Id查询店铺信息
        ShopShopInfo shopShopInfo = shopShopInfoService.loadShopShopInfo(shopProductInfo.getShopInfoId());
        //查询品牌信息
        ShopBrand shopBrand = shopBrandService.loadShopBrand(shopProductInfo.getBrandId());
        //查询店铺内部分类
        List<Map<String,Object>> proCategoryList= shopShopProCategoryService.queryProCategoryNameByProductId(shopProductInfo.getProductId());
        if (Utils.collectionIsNotEmpty(proCategoryList)) {
            resultMap.put("shopProCategoryName", proCategoryList.get(0).get("shopProCategoryName"));
        }
        //关联查询商品属性信息
        List<Map<String, Object>> attrList = shopProductAttributeService.queryProductAttributeList(productId);
        Map<String, Object> prodTypeName =getProductTypeName(shopProductInfo.getProductTypeId());
        resultMap.put("productRelationMap",productRelationMap);
        resultMap.put("shopBrand",shopBrand);
        resultMap.put("shopShopInfo",shopShopInfo);
        resultMap.put("productTypeName",prodTypeName);
        resultMap.put("attrList",attrList);
        return resultMap;
    }

    /**
     * 商品审核操作
     * @param shopProductInfo
     * @param usersName
     * @return
     */
    @Override
    public boolean auditProduct(ShopProductInfo shopProductInfo,String usersName){
        boolean success=false;
        Map<String,Object> params=new HashMap<>();
        //判断商品及商品Id不为空
        if(Utils.objectIsNotEmpty(shopProductInfo) && Utils.objectIsNotEmpty(shopProductInfo.getProductId()) && Utils.objectIsNotEmpty(usersName)){
            //根据商品Id查询商品对象
            ShopProductInfo shopProductInfo_temp = loadShopProductInfo(shopProductInfo.getProductId());
            shopProductInfo_temp.setIsTop(shopProductInfo.getIsTop()); //是否为顶置商品
            shopProductInfo_temp.setIsPass(shopProductInfo.getIsPass());//商品审核状态
            shopProductInfo_temp.setIsPutSale(shopProductInfo.getIsPutSale()); //是否上架
            //如果是否上架状态为2时，插入上架时间
            if(shopProductInfo.getIsPutSale()==2){
                shopProductInfo_temp.setPutSaleDate(new Timestamp(System.currentTimeMillis()));//上架时间
            }
            shopProductInfo_temp.setIsRecommend(shopProductInfo.getIsRecommend());//是否为推荐商品
            shopProductInfo_temp.setIsShow(shopProductInfo.getIsShow()); //是否显示在列表
            shopProductInfo_temp.setPassUserName(usersName);//审核人名称
            shopProductInfo_temp.setUpdateDate(new Timestamp(System.currentTimeMillis()));  //商品修改时间，获取当前系统时间
            shopProductInfo_temp.setAuditComment(shopProductInfo.getAuditComment());//审核备注
            //判断当审核状态为1（审核通过）时，为该商品生成二维码
            if(shopProductInfo_temp.getIsPass()==1){
                //从redis中获取手机微信项目路径
                String basePath = RedisDataReadUtil.getSysConfig("phoneBasePath");
                //组拼二维码的路径
                String addUrl = basePath + StringStaticKey.WX_PHONE_PRODUCT_INFO_PRODUCT_ID_URL + shopProductInfo_temp.getProductId();
                //生成二维码
                String codeUrl= QRCode.createQRPng(addUrl,null,RedisDataReadUtil.getSysConfig("fileUploadRoot"),"shop","image_product");
                //商品对象放入二维码
                shopProductInfo_temp.setQrCode(codeUrl);
            }
            //修改商品审核状态相关操作
            updateBasicShopProductInfo(shopProductInfo_temp);
            success=true;
        }
        return success;
    }

    /**
     * 修改商品返利操作
     * @param shopProductInfo
     * @return
     */
    @Override
    public boolean updateProductRatio(ShopProductInfo shopProductInfo){
        boolean success=false;
        //判断商品及商品Id不为空
        if(Utils.objectIsNotEmpty(shopProductInfo) && Utils.objectIsNotEmpty(shopProductInfo.getProductId())){
            //根据商品Id查询商品对象
            ShopProductInfo shopProductInfo_temp = loadShopProductInfo(shopProductInfo.getProductId());
            shopProductInfo_temp.setUpRatio(shopProductInfo.getUpRatio()); //一级返利
            shopProductInfo_temp.setSecRatio(shopProductInfo.getSecRatio()); //二级返利
            shopProductInfo_temp.setThiRatio(shopProductInfo.getThiRatio()); //三级返利
            //修改商品审核状态相关操作
            updateBasicShopProductInfo(shopProductInfo_temp);
            success=true;
        }
        return success;
    }

    /**
     * 批量生成二维码操作
     * @param shopInfoProductType 店铺类型：1 自营，2 入驻
     * @param response
     * @return
     */
    @Override
    public Map<String,Object> productInfoGeneratedQrCode(Integer shopInfoProductType,HttpServletResponse response){
        boolean success = false;
        Map<String,Object> resultMap=new HashMap<>();
        Map<String,Object> params=new HashMap<>();
        String failureLog1 = "";
        String failureLog2 = "";
        String phoneBasePath = RedisDataReadUtil.getSysConfig("phoneBasePath"); //从redis中获取手机微信项目路径
        if (Utils.objectIsNotEmpty(phoneBasePath) && Utils.objectIsNotEmpty(shopInfoProductType)) { //判断手机微信项目路径与店铺类型不为空，
            String basePath = String.valueOf(phoneBasePath);
            params.put("shopInfoProductType",shopInfoProductType);
            List<ShopProductInfo> shopProductInfoList = queryShopProductInfo(params); //根据店铺类型查询商品集合
            if (Utils.objectIsNotEmpty(shopProductInfoList) && shopProductInfoList.size() > 0) { //判断集合不为空
                int size = shopProductInfoList.size();
                for (int i = 0; i < size; i++) {
                    if (Utils.objectIsNotEmpty(shopProductInfoList.get(i).getProductId())) {//判断商品id不为空
                        //组拼二维码的路径
                        String addUrl = basePath + StringStaticKey.WX_PHONE_PRODUCT_INFO_PRODUCT_ID_URL + shopProductInfoList.get(i).getProductId();
                        //生成二维码
                        String codeUrl= QRCode.createQRPng(addUrl,null,RedisDataReadUtil.getSysConfig("fileUploadRoot"),"shop","image_product");
                        params.clear();
                        params.put("productId",shopProductInfoList.get(i).getProductId());
                        params.put("qrCode",codeUrl);
                        boolean flag=updateProductQRCode(params);//根据商品Id更新二维码
                        if (!flag) {
                            if (i == size - 1) {
                                failureLog2 += shopProductInfoList.get(i).getProductName();
                            } else {
                                failureLog2 += shopProductInfoList.get(i).getProductName() + ",";
                            }
                        }
                    }
                }
            }else {
                failureLog1 = "生成失败！";
            }
        }
        resultMap.put("failureLog1",failureLog1);
        if (Utils.objectIsNotEmpty(failureLog2)) {
            resultMap.put("failureLog2", "商品名称为：" + failureLog2 + "的记录生成失败！");
        } else {
            resultMap.put("failureLog2", failureLog2);
        }
        success = Utils.objectIsEmpty(failureLog1) && Utils.objectIsEmpty(failureLog2);
        resultMap.put("success",success);
        return resultMap ;
    }


    /**
     * 更新商品二维码，供批量生成二维码方法调用二维码
     * @param params
     * @return
     */
    public boolean updateProductQRCode(Map<String,Object> params){
        boolean success=false;
        int update = shopProductInfoDAO.update("updateProductQRCode", params);
        if(update>0){
            success=true;
        }
        return success;
    }

    /**
     * 删除商品及关联数据
     * @param productId
     * @return
     */
    @Override
    public boolean deleteProductAll(Integer productId){
        boolean success=false;
        shopProductInfoDAO.deleteProductInfoById(productId);
        success=true;
        return success;
    }

    /**
     * 递归查询商品分类名称
     * @param prodTypeId
     * @return
     */
    public Map<String,Object> getProductTypeName(Integer prodTypeId){
        Map<String,Object> resultMap=new HashMap<>();
        ShopProductType shopProductType3 = shopProductTypeService.loadShopProductType(prodTypeId);
        if (Utils.objectIsNotEmpty(shopProductType3)) {
            resultMap.put("level3Name", shopProductType3.getSortName());
            ShopProductType shopProductType2 = shopProductTypeService.loadShopProductType(shopProductType3.getParentId());
            if (Utils.objectIsNotEmpty(shopProductType2)){
                resultMap.put("level2Name", shopProductType2.getSortName());
                ShopProductType shopProductType1 = shopProductTypeService.loadShopProductType(shopProductType2.getParentId());
                if (Utils.objectIsNotEmpty(shopProductType1)){
                    resultMap.put("level1Name", shopProductType1.getSortName());
                }
            }
        }
        return resultMap;
    }

    /**
     * 去掉商品组图中因为springmvc封装的结合存在不需要的对象
     * @param productImgList
     * @return
     */
    public List<ShopProductImg> removeNullObjectForImageList(List<ShopProductImg> productImgList){
        List <ShopProductImg> productImageList =new ArrayList<ShopProductImg>();
        for(ShopProductImg spi:productImgList){
            if(Utils.objectIsNotEmpty(spi.getTitle()) && Utils.objectIsNotEmpty(spi.getOrders()) && Utils.objectIsNotEmpty(spi.getSource())){
                productImageList.add(spi);
            }
        }
        return productImageList;
    }
}